<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  

    <div class="row">
      <div class="col-sm-12">
        <div class="well">
          <%= simple_form_for :account_signin, url: admin_account_signins_path, :defaults => { :input_html => { :class => "form-control" } },  method: 'get', html: { class: "form-inline" } do |f| %>
            <label>设备组</label>
            <%= f.input_field :terminal_group, collection: TerminalGroup.all.inject([['全部','all']]){|tgs,tg| tgs << [tg.group_name,tg.id]}, selected: (params[:account_signin][:terminal_group] || 'all') %>
            <label>日期类型</label>
            <%= f.input_field :date_part, collection: date_parts.collect{|k,v| [v,k]}, selected: (params[:account_signin][:date_part] || 'month') %>
            <label>注册时间</label>
            <div class="form-group string">
              <%= f.text_field :start_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:account_signin][:start_date], placeholder: "From" %>
            </div>
            <div class="form-group string">
              <%= f.text_field :end_date, class: 'form-control datepicker', "data-dateformat" => "yy-mm-dd", value: params[:account_signin][:end_date], placeholder: "To" %>
            </div>
            <%= f.submit "搜索", :class => "btn btn-default"%>
          <% end %>
        </div> <!-- end well div -->

      </div>
    </div>

    <!-- row -->
    <div class="row">
  
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
  
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>签到列表</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <div class="alert alert-info no-margin">
                <span class="">
                  <i class="fa-fw fa fa-info"></i>共有<%= @account_signins.sum{|i| i.total.to_i} %>次签到
                </span>
                <span class="col-md-offset">
                  <a class="btn btn-default btn-sm" href="<%= admin_account_signins_path({format: :csv}.merge!(params)) %>">导出为CSV</a>
                </span>
              </div>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>终端组/终端</th>
                    <% if params[:account_signin][:date_part] != 'year' %>
                      <th>年</th>
                    <% end %>
                    <th><%= date_parts[(params[:account_signin][:date_part] || 'month')] %></th>
                    <th>次数</th>
                  </tr>
                </thead>
                <tbody>
                  <% if params[:account_signin][:terminal_group] == 'all' %>
                    <% @account_signins.group_by{|account_signin| [account_signin.created_year,account_signin.created_part] }.each do |created_attrs,account_signins| %>
                      <tr>
                        <td>
                          <%= "全部" %>
                        </td>
                        <% if params[:account_signin][:date_part] != 'year' %>
                          <td><%= created_attrs[0] %></td>
                        <% end %>
                        <td>
                          <%= created_attrs[1] %> 
                        </td>
                        <td>
                          <%= account_signins.sum{|i| i.total.to_i} %> 
                        </td>
                      </tr>
                    <% end %>
                  <% else %>
                    <% @account_signins.each do |account_signin| %>
                      <tr>
                        <td>
                          <% if account_signin.terminal.present? %>
                            <%= account_signin.terminal.try(:terminal_group) ? account_signin.terminal.terminal_group.group_name : account_signin.terminal.mac %>
                          <% end %>
                        </td>
                        <% if params[:account_signin][:date_part] != 'year' %>
                          <td><%= account_signin.created_year %></td>
                        <% end %>
                        <td>
                          <%= account_signin.created_part %> 
                        </td>
                        <td>
                          <%= account_signin.total %> 
                        </td>
                      </tr>
                    <% end %>
                  <% end %>
                </tbody>
              </table>
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->

      <% if @signin_chart_attrs %>
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-2" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
  
          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"
  
          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-bar-chart-o"></i> </span>
            <h2><%= @signin_chart_attrs[:title] %></h2>
  
          </header>
  
          <!-- widget div-->
          <div>
  
            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
  
            </div>
            <!-- end widget edit box -->
  
            <!-- widget content -->
            <div class="widget-body no-padding">

              <%= render :partial => 'charts/line_container',:locals => {:chart_attrs => @signin_chart_attrs,:page_id => 'signin_'} %>
  
            </div>
            <!-- end widget content -->
  
          </div>
          <!-- end widget div -->
  
        </div>
        <!-- end widget -->
        
      </article>
      <!-- WIDGET END -->
      <% end %>
    </div>
  
    <!-- end row -->

  </section>
  <!-- end widget grid -->
<% end %>